<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>角色管理--${fns:getConfig('productName')}</title>
<%@ include file="/common/treeview.jsp"%>
<script type="text/javascript">
$(document).ready(function(){
	$("#roleName").focus();
	$("#inputForm").validate({
		rules: {
			roleName: {
				remote:"${ctx}/role/check.do?oldName=" + encodeURIComponent("${role.roleName}")
			}
		},
		messages: {
			roleName: {remote: "角色名已存在"}
		},
		submitHandler:function(form){
			var ids = [], nodes = tree.getCheckedNodes(true);
			for(var i=0; i<nodes.length; i++) {
				ids.push(nodes[i].id);
			}
			$("#menuIds").val(ids);
			loading("保存角色中...");
			form.submit();
		},
		errorContainer: "#messageBox",
		errorPlacement: function(error, element) {
			$("#messageBox").text("输入有误，请先更正。");
			if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
				error.appendTo(element.parent().parent());
			} else {
				error.insertAfter(element);
			}
		}
	});
	var setting={check:{enable:true,nocheckInherit:true},view:{selectedMulti:false},
			data:{simpleData:{enable:true}},callback:{beforeClick:function(id, node){
				tree.checkNode(node, !node.checked, true, true);
				return false;
			}}};
	
	// 用户-菜单
	var zNodes=[
			<c:forEach items="${menuList}" var="menu">{
				id:"${menu.id}", 
				pId:"${not empty menu.parent.id?menu.parent.id:0}", 
				name:"${not empty menu.parent.id?menu.name:'权限列表'}"
				      +"${not empty menu.remark?'[':''}"
				      +"${not empty menu.remark?menu.remark:''}"
				      +"${not empty menu.remark?']':''}"
				},
            </c:forEach>];
	// 初始化树结构
	var tree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
	// 默认选择节点
	var ids = "${role.menuIds}".split(",");
	for(var i=0; i<ids.length; i++){
		var node = tree.getNodeByParam("id", ids[i]);
		try{tree.checkNode(node, true, false);}catch(e){}
	}
	// 默认展开全部节点
	//tree.expandAll(true);
});
</script>
</head>
<body>
	<ul class="nav nav-tabs" style="margin:0 4px;margin-bottom:15px;">
		<li><a href="${ctx}/role/list.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}"> <i
				class="icon icon-list"></i>&nbsp;<span>角色列表</span>
		</a></li>
		<sec:authorize ifAnyGranted="ROLE_sys_menu_edit">
		<li class="active"><a
			href="${ctx}/role/input.do?id=${fns:encodeParam(role.id)}&top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}"> <i
				class="icon icon-edit"></i>&nbsp;<span>角色${not empty
				role.id?'修改':'添加'}</span>
		</a></li>
		</sec:authorize>
	</ul>
	<br />
	<form id="inputForm" action="${ctx}/role/save.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}"
		method="post" class="form-horizontal propertyHeight" style="width:auto;overflow:auto;">
		<input type="hidden" name="id" value="${role.id}" />
		<input type="hidden" name="token" value="${token}">
		<div class="control-group">
			<label class=" control-label">英文名称<font style="color:red;">*</font>:</label>
			<div class="controls">
			    <input id="oldName" name="oldName" type="hidden" value="${role.roleName}">
				<input class="required" id="roleName" name="roleName"
					type="text" value="${role.roleName}">
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">中文名称<font style="color:red;">*</font>:</label>
			<div class="controls">
				<input class=" required" id="roleDesc" name="roleDesc"
					type="text" value="${role.roleDesc}">
			</div>
		</div>
<!-- 		<div class="control-group"> -->
<!-- 			<label class=" control-label">角色类别<font style="color:red;">*</font>:</label> -->
<!-- 			<div class="controls"> -->
<%-- 				<pt:code name="category" category="2007" hasEmpty="true" prompt="" default="${role.category}"></pt:code> --%>
<!-- 			</div> -->
<!-- 		</div> -->
		<div class="control-group">
			<label class=" control-label">是否启用:</label>
			<div class="controls">
				<pt:code name="useFlag" category="1000"  default="${role.useFlag}"></pt:code>
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">备注:</label>
			<div class="controls">
				<input class="" id="remark" name="remark"
					type="text" value="${role.remark}">
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">角色授权:</label>
			<div class="controls">
				<div id="menuTree" class="ztree"
					style="margin-top: 3px; float: left;"></div>
				<input type="hidden" id="menuIds" name="menuIds" value="${role.menuIds}" />
			</div>
		</div>

		<div class="form-actions">
<%-- 		<sec:authorize ifAnyGranted="ROLE_sys_role_edit"> --%>
				<input id="btnSubmit" class="btn btn-primary" type="submit"
					value="保 存" />
					&nbsp; <input id="btnCancel" class="btn"
					type="button" value="返 回" onclick="toBack()" />
<%-- 		</sec:authorize> --%>
		</div>
	</form>
</body>
</html>